Repository navigation
Conversation
Add a Perforce backend for p4://host[:port]/depot/path and p4+ssl://host[:port]/depot/path URLs (default port 1666), also selectable with --vcs=p4 or ghq.<url>.vcs = p4. "ghq get" creates a client whose root is the local directory and whose view maps //depot/path/... into it, records P4PORT/P4CLIENT (and P4USER from the URL) in .p4config, and runs "p4 sync". "ghq get -u" runs "p4 sync" with the server and client from .p4config passed explicitly. .p4config marks the workspace for "ghq list". "ghq migrate" updates the root of the client. Client names are <user>_<hostname>_<depot path>_<hash>; an existing client is reused only when its root is the target directory. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Accept only tcp/ssl P4PORT forms from .p4config and URLs; a P4PORT such as rsh:<command> made p4 run a local command. - Treat .p4config as a workspace only if it names a valid client, so shared P4CONFIG files no longer hide repositories below them. - Check that the client exists and is rooted at the workspace before "get -u" and RemoteURL; p4 sync writes to the root on the server. - Refuse "get -u" with a p4:// URL of another server or user (ghq paths omit the port). - Claim the workspace directory exclusively before running p4, and remove only that directory on failure. - Reject URL fragments and queries (p4://host/path#rev used to sync head). - Hash the raw user and hostname into client names. - migrate: fail and move the workspace back if the client root cannot be updated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Clone: until "p4 sync" starts, clean up only .p4config and the directory if still empty, so a nested checkout created meanwhile is never deleted; keep a workspace whose sync failed for "ghq get -u". - get -u: reject @revision (the getter now passes it to Update) and a p4:// URL whose depot path is not the client's (ghq strips ".git"). - migrate: capture the client root before moving and compare the server's value afterwards; after a failed save, re-read the client to tell an applied save (lost reply) from an unchanged one before moving back, and leave the workspace in place when the outcome is unknown. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Clone: clear a reused client's have list with "sync -k //client/...#none" and run a plain sync instead of "sync -f", so that an interrupted sync is resumed correctly by "ghq get -u". - Reject p4+ schemes other than p4+ssl instead of falling back to TCP. - get -u: check the user, an explicit port and the depot path of every URL, not only p4:// ones (e.g. --vcs=p4 with an https URL); allow URLs of directories inside the workspace. - migrate: treat a client already rooted at the destination as moved, and do not move the workspace back when its root was changed by others. - list: ignore .p4config in a root or <host> directory, where ghq never creates p4 workspaces, so shared settings naming a client do not hide other repositories. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This adds a Perforce backend, so depot paths can be managed with ghq like any other repository:
Design
p4://[user@]host[:port]/depot/path(P4PORThost:port, default port 1666) andp4+ssl://…(P4PORTssl:host:port). The local path is<root>/<host>/depot/path; ghq already drops theport.
--vcs=p4/perforceandghq.<url>.vcs = p4also work, treating other schemes as plain TCP. The following arerejected before p4 is run: depot paths with p4 wildcards or revision specifiers (
...,*,@,#,%), quotes,control characters or empty/
./..components; URL fragments and queries; unknownp4+schemes; and passwords.p4 client -o <name>, then setRootto the target directory andViewto"//depot/path/..." "//<name>/..."(plus an exclusion of a depot.p4config), thenp4 client -ivia stdin,then write
<root>/.p4configwithP4PORT/P4CLIENT(andP4USERif the URL has a user), thenp4 sync.-p,-c(and-u) are always passed explicitly, soP4PORT/P4CLIENT/P4CONFIGfrom the environment neverredirect ghq to another server or client.
<user>_<hostname>_<depot path slug>_<hash>, sanitized to[A-Za-z0-9_-]. The hash coversall inputs (user, hostname, server, depot path, local root), so names stay unique after sanitizing and truncating.
An existing client with that name is reused only if its
Rootis the target directory (e.g. afterghq rm).Its stale have list is then cleared with
p4 sync -k //<client>/...#nonebefore syncing. Any othersame-named client is left untouched and ghq refuses.
mkdir. Before the sync starts, a failure removesonly ghq's
.p4configand the directory if it is still empty. Ifp4 syncitself fails, the workspace is kept andghq get -uresumes it. p4's own messages (no login, connection failures, rejected views) are shown.p4 syncwith the server and client from.p4config, after checking that the client still exists and isrooted at the workspace (
p4 syncwrites to the root recorded on the server). Because ghq paths omit the port anda trailing
.git, a URL naming another server, user or depot path that maps to the same directory is refused..p4configmarks a workspace if it names a client with a tcp/ssl P4PORT. It is checked after every otherbackend's marker. Shared P4CONFIG files without a client, or in a root or
<host>directory, don't hide the repositoriesbelow them. A
P4PORTsuch asrsh:<command>is never passed to p4.RemoteURLrebuilds thep4://URL from.p4configand the client view. migrate checks that theclient is rooted at the source, moves the workspace and updates the client's
Root. If the update fails, migratere-reads the client and moves the workspace back only when the old root is confirmed.
ghq create(no Init, like CVS),--branch/@revision,--bare(clear errors);--shallow,--partialand--no-recursiveare ignored, since a workspace only holds synced revisions anyway.getter.gonow passes the@branchpart of the URL toUpdatetoo, so it can be rejected there; the otherbackends ignore it in
Update, as before.p4, README section, shell completions.Follow-ups (out of scope)
ghq rmremoves only the local directory; the client spec stays on the server (p4 client -d <name>). Deleting itneeds care with opened files and shelved changes, so it's left for a follow-up. A later
ghq getreuses the client.--branchfor streams.P4CLIENTPATHfor ghq's p4 calls, as defence in depth against a misbehaving server.Testing
CommandRunnerstyle, including a small in-memory p4 server (client specs and have lists).They cover the command sequence and client spec contents; client reuse and collisions; failure cleanup (no login,
rejected spec, failed or interrupted sync, concurrent nested checkout); URL validation and P4PORT mapping;
.p4configparsing and validation;RemoteURL; client-name sanitizing;get -uidentity and root checks;migrate rollback (rejected save, lost reply, unknown outcome, symlinked source); and URL/detection/list/create/get/rm tests.
go test ./...,go vet ./..., staticcheck, misspell and typos pass.checks, transcript below.
e2e transcript
🤖 Generated with Claude Code